﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RoboticOperationMerge.CApROMMerger
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.InsertLocationInsideSeam;
using EngineeringInternalExtension;
using EngineeringInternalExtension.ModelObjects;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.RoboticOperationMerge;

internal class CApROMMerger
{
  private bool m_previewLog;
  private bool m_isTheFirstTime = true;
  private bool m_isExcelIntropInstalled;
  private bool m_projectionParamatersExist;
  private bool m_mergeAtLeastOneOperation;
  private bool m_mergeAtLeastOneViaLoc;
  private bool m_mergeAtLeastOneDefaultLoc;
  private bool m_mergeAtLeastOneAlternateLoc;
  private bool m_insertAtLeastOneSeamLoc;
  private List<Tuple<string, string, RemoveAction>> m_removedObjectNameData = new List<Tuple<string, string, RemoveAction>>();
  private ITxObjectCollection m_weldLocationContainer;
  private CApROMExcelManager m_excelManager = new CApROMExcelManager();

  internal CApROMMerger(bool isPreview = false)
  {
    this.m_previewLog = isPreview;
    this.m_isTheFirstTime = true;
    this.m_isExcelIntropInstalled = TxAssemblyInfoEx.IsExcelInstalled(false, "");
  }

  internal void Merge(
    ITxOrderedObjectCollection oldTargetOperation,
    TxObjectList removedLocations,
    CApROMMergeInfo[] newTargetOp,
    ITxObjectCollection weldLocationContainer)
  {
    this.InitForMerge(newTargetOp, weldLocationContainer);
    this.CheckIfProjectionParamsExist(newTargetOp);
    if (this.m_insertAtLeastOneSeamLoc && !this.m_projectionParamatersExist)
    {
      TxMessageBox.Show(this.GetResourceManager().GetString("WARNING_NO_PROJECTION_PARAMS"), this.GetResourceManager().GetString("WARNING_CAPTION"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    else
    {
      if (this.m_isExcelIntropInstalled)
      {
        this.m_excelManager.AddCall(new Action(this.m_excelManager.InitExcel));
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.InitColumnHeaders(new Func<bool>(this.ShouldInsertNameColumn), new Func<bool>(this.ShouldInsertPositionColumn), new Func<bool>(this.ShouldInsertOrientationColumn), new Func<bool>(this.ShouldInsertExternalAxisColumn), new Func<bool>(this.ShouldInsertOLPCommandsColumn), new Func<bool>(this.ShouldInsertRoboticParametersColumn), new Func<bool>(this.ShouldInsertTaughtPositionAndOrientationColumn), new Func<bool>(this.ShouldInsertConfigurationColumn), new Func<bool>(this.ShouldInsertAttributesColumn))));
      }
      Cursor current = Cursor.Current;
      Cursor.Current = Cursors.WaitCursor;
      if (!this.m_previewLog)
        TxApplication.ActiveUndoManager.StartTransaction();
      switch (oldTargetOperation)
      {
        case ITxContinuousOperation _:
          this.MergeContOp(oldTargetOperation, removedLocations, newTargetOp);
          break;
        case TxRoboticSeamOperation _:
          this.MergeSeamOp(oldTargetOperation, removedLocations, newTargetOp);
          break;
        default:
          this.MergeWeldOp(oldTargetOperation, removedLocations, newTargetOp);
          break;
      }
      this.LogRemovedObjects();
      if (!this.m_previewLog)
        TxApplication.ActiveUndoManager.EndTransaction();
      Cursor.Current = current;
    }
  }

  internal void MergeWeldOp(
    ITxOrderedObjectCollection oldTargetOperation,
    TxObjectList removedLocations,
    CApROMMergeInfo[] newTargetOp)
  {
    bool flag1 = ((Collection<ITxObject>) removedLocations).Count > 0 && oldTargetOperation is ITxWeldLocationOperationCreation;
    List<string> stringList1 = (List<string>) null;
    Dictionary<string, ITxObject> dictionary = (Dictionary<string, ITxObject>) null;
    if (flag1)
    {
      int count = ((ITxObjectCollection) oldTargetOperation).Count;
      stringList1 = new List<string>(count);
      dictionary = new Dictionary<string, ITxObject>(count);
      for (int index = 0; index < count; ++index)
        stringList1.Add(oldTargetOperation.GetChildAt(index).Id);
    }
    if (!this.m_previewLog)
    {
      foreach (ITxObject removedLocation in (Collection<ITxObject>) removedLocations)
      {
        if (removedLocation is ITxRoboticOperation)
        {
          if (flag1 && removedLocation is TxWeldLocationOperation)
          {
            int count = ((ITxObjectCollection) oldTargetOperation).Count;
            int indexOfChild = oldTargetOperation.GetIndexOfChild(removedLocation);
            string id = removedLocation.Id;
            this.removeLocationOperation(removedLocation);
            if (count == ((ITxObjectCollection) oldTargetOperation).Count)
            {
              ITxObject childAt = oldTargetOperation.GetChildAt(indexOfChild);
              if (!stringList1.Contains(childAt.Id))
                dictionary.Add(id, childAt);
            }
          }
          else if (removedLocation.CanBeDeleted)
          {
            this.AddRemovedObjectToNameData(removedLocation, RemoveAction.Deleted);
            removedLocation.Delete();
          }
        }
      }
    }
    ITxRoboticOperation roboticOperation1 = (ITxRoboticOperation) null;
    ITxRoboticOperation roboticOperation2 = (ITxRoboticOperation) null;
    for (int index = 0; index < newTargetOp.Length; ++index)
    {
      bool flag2 = true;
      CApROMMergeInfo capRomMergeInfo = newTargetOp[index];
      if (capRomMergeInfo.TargetObject != null)
      {
        if (index != 0 && ((ITxObjectCollection) oldTargetOperation).Count > index && capRomMergeInfo.TargetObject != oldTargetOperation.GetChildAt(index - 1) && roboticOperation1 != null && !this.m_previewLog)
        {
          if (index == 1)
          {
            if (((ITxObjectCollection) oldTargetOperation).Count > 2 && oldTargetOperation.CanMoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, oldTargetOperation.GetChildAt(0)))
              oldTargetOperation.MoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, oldTargetOperation.GetChildAt(0));
            if (oldTargetOperation.CanMoveChildAfter(oldTargetOperation.GetChildAt(0), (ITxObject) capRomMergeInfo.TargetObject))
              oldTargetOperation.MoveChildAfter(oldTargetOperation.GetChildAt(0), (ITxObject) capRomMergeInfo.TargetObject);
          }
          else if (oldTargetOperation.CanMoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, (ITxObject) roboticOperation1))
            oldTargetOperation.MoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, (ITxObject) roboticOperation1);
        }
        if (capRomMergeInfo.MatchedObject != null)
          this.CopyData(oldTargetOperation, capRomMergeInfo.MatchedObject, capRomMergeInfo.TargetObject, capRomMergeInfo.MergeSchema);
        roboticOperation1 = capRomMergeInfo.TargetObject;
      }
      else
      {
        if (!this.m_previewLog)
        {
          TxObjectList txObjectList = new TxObjectList();
          ((Collection<ITxObject>) txObjectList).Add((ITxObject) capRomMergeInfo.MatchedObject);
          ((ITxObjectCollection) oldTargetOperation).Paste(txObjectList);
          if (((ITxObjectCollection) oldTargetOperation).Count > 1)
          {
            if (index > 1)
            {
              flag2 = oldTargetOperation.CanMoveChildAfter(oldTargetOperation.GetChildAt(((ITxObjectCollection) oldTargetOperation).Count - 1), (ITxObject) roboticOperation1);
              roboticOperation2 = roboticOperation1;
            }
            else if (index == 1)
            {
              flag2 = true;
              roboticOperation2 = oldTargetOperation.GetChildAt(0) as ITxRoboticOperation;
            }
          }
          else
            flag2 = false;
          if (capRomMergeInfo.MatchedObject != null)
            this.CopyData(oldTargetOperation, (ITxRoboticOperation) null, oldTargetOperation.GetChildAt(((ITxObjectCollection) oldTargetOperation).Count - 1) as ITxRoboticOperation, capRomMergeInfo.MergeSchema);
          roboticOperation1 = oldTargetOperation.GetChildAt(((ITxObjectCollection) oldTargetOperation).Count - 1) as ITxRoboticOperation;
          if (flag2)
            oldTargetOperation.MoveChildAfter(oldTargetOperation.GetChildAt(((ITxObjectCollection) oldTargetOperation).Count - 1), (ITxObject) roboticOperation2);
        }
        if (this.m_previewLog && capRomMergeInfo.MatchedObject != null)
          this.CopyData(oldTargetOperation, (ITxRoboticOperation) null, capRomMergeInfo.MatchedObject, capRomMergeInfo.MergeSchema);
      }
    }
    if (!flag1 || dictionary.Count <= 0)
      return;
    int count1 = ((ITxObjectCollection) oldTargetOperation).Count;
    if (count1 <= 1)
      return;
    Dictionary<string, ITxObject>.Enumerator enumerator = dictionary.GetEnumerator();
    while (enumerator.MoveNext())
    {
      int num = -1;
      ITxObject itxObject1 = (ITxObject) null;
      List<string> stringList2 = stringList1;
      KeyValuePair<string, ITxObject> current = enumerator.Current;
      string key = current.Key;
      for (int index1 = stringList2.IndexOf(key) - 1; index1 >= 0 && num < 0; --index1)
      {
        string id = stringList1[index1];
        if (dictionary.ContainsKey(id))
          id = dictionary[id].Id;
        for (int index2 = 0; index2 < count1 && num < 0; ++index2)
        {
          ITxObject childAt = oldTargetOperation.GetChildAt(index2);
          if (id == childAt.Id)
          {
            num = index2;
            itxObject1 = childAt;
          }
        }
      }
      if (!this.m_previewLog)
      {
        current = enumerator.Current;
        ITxObject itxObject2 = current.Value;
        if (oldTargetOperation.GetIndexOfChild(itxObject2) != num + 1)
        {
          if (itxObject1 != null)
          {
            if (oldTargetOperation.CanMoveChildAfter(itxObject2, itxObject1))
              oldTargetOperation.MoveChildAfter(itxObject2, itxObject1);
          }
          else
          {
            ITxObject childAt = oldTargetOperation.GetChildAt(0);
            if (oldTargetOperation.CanMoveChildAfter(itxObject2, childAt))
            {
              oldTargetOperation.MoveChildAfter(itxObject2, childAt);
              if (oldTargetOperation.CanMoveChildAfter(childAt, itxObject2))
                oldTargetOperation.MoveChildAfter(childAt, itxObject2);
            }
          }
        }
      }
    }
  }

  private void removeLocationOperation(ITxObject location)
  {
    if (location.CanBeDeleted)
    {
      this.AddRemovedObjectToNameData(location, RemoveAction.Deleted);
      location.Delete();
    }
    else if (this.m_weldLocationContainer != null)
    {
      if (this.m_weldLocationContainer.CanBeAdded(location))
      {
        this.m_weldLocationContainer.AddObject(location);
        this.AddRemovedObjectToNameData(location, RemoveAction.Moved);
      }
      else
        this.AddRemovedObjectToNameData(location, RemoveAction.Denied);
    }
    else
    {
      TxWeldLocationOperation locationOperation = location as TxWeldLocationOperation;
      if (!TxWeldLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
        return;
      TxWeldPoint weldPoint = locationOperation.WeldPoint;
      if (!TxWeldPoint.op_Inequality(weldPoint, (ITxObject) null) || !((TxMfgFeature) weldPoint).CanBeDeleted)
        return;
      this.AddRemovedObjectToNameData(location, RemoveAction.Deleted);
      this.AddRemovedObjectToNameData((ITxObject) weldPoint, RemoveAction.Deleted);
      ((TxMfgFeature) weldPoint).Delete();
    }
  }

  internal void MergeSeamOp(
    ITxOrderedObjectCollection oldTargetOperation,
    TxObjectList removedLocations,
    CApROMMergeInfo[] newTargetOp)
  {
    if (!this.m_previewLog)
    {
      foreach (ITxObject removedLocation in (Collection<ITxObject>) removedLocations)
      {
        if (removedLocation is ITxRoboticOperation && removedLocation.CanBeDeleted)
          removedLocation.Delete();
      }
    }
    CApROMMergeInfo capRomMergeInfo1 = newTargetOp[0];
    if (capRomMergeInfo1.MatchedObject != null)
      this.CopyData(oldTargetOperation, capRomMergeInfo1.MatchedObject, capRomMergeInfo1.TargetObject, capRomMergeInfo1.MergeSchema);
    int i_child = -1;
    for (int i_currNode = 1; i_currNode < newTargetOp.Length; ++i_currNode)
    {
      CApROMMergeInfo capRomMergeInfo2 = newTargetOp[i_currNode];
      if (capRomMergeInfo2.TargetObject != null)
      {
        if (!this.m_previewLog)
          this.ReorderInSeamOpTarget(oldTargetOperation, ref i_child, i_currNode, newTargetOp);
        if (capRomMergeInfo2.MatchedObject != null)
          this.CopyData(oldTargetOperation, capRomMergeInfo2.MatchedObject, capRomMergeInfo2.TargetObject, capRomMergeInfo2.MergeSchema);
      }
      else if (capRomMergeInfo2.MatchedObject != null)
      {
        ITxLocatableObject matchedObject = capRomMergeInfo2.MatchedObject as ITxLocatableObject;
        if (!this.m_previewLog)
        {
          if (this.InsertSeamLocToSeamOp(matchedObject, oldTargetOperation as TxRoboticSeamOperation, i_child + 1))
          {
            ++i_child;
            this.CopyData(oldTargetOperation, (ITxRoboticOperation) null, oldTargetOperation.GetChildAt(i_child) as ITxRoboticOperation, capRomMergeInfo2.MergeSchema);
          }
        }
        else
          this.CopyData(oldTargetOperation, (ITxRoboticOperation) null, matchedObject as ITxRoboticOperation, capRomMergeInfo2.MergeSchema);
      }
    }
  }

  internal void MergeContOp(
    ITxOrderedObjectCollection oldTargetOperation,
    TxObjectList removedObjects,
    CApROMMergeInfo[] newTargetOp)
  {
    if (!this.m_previewLog)
      this.DeleteRemovedObjectsFromContOp(removedObjects);
    CApROMMergeInfo capRomMergeInfo = newTargetOp[0];
    if (capRomMergeInfo.MatchedObject != null)
      this.CopyData(oldTargetOperation, capRomMergeInfo.MatchedObject, capRomMergeInfo.TargetObject, capRomMergeInfo.MergeSchema);
    int i_child = -1;
    for (int i_currNode = 1; i_currNode < newTargetOp.Length; ++i_currNode)
    {
      CApROMMergeInfo currNode = newTargetOp[i_currNode];
      if (currNode.TargetObject != null)
      {
        if (!(currNode.TargetObject is TxRoboticSeamLocationOperation))
        {
          this.ReorderInContOpTarget(oldTargetOperation, ref i_child, i_currNode, newTargetOp);
          if (currNode.MatchedObject != null)
            this.CopyData(oldTargetOperation, currNode.MatchedObject, currNode.TargetObject, currNode.MergeSchema);
        }
      }
      else if (currNode.MatchedObject != null && !(currNode.MatchedObject is TxRoboticSeamLocationOperation))
      {
        if (!this.m_previewLog)
        {
          this.CreateInTarget(oldTargetOperation, ref i_child, currNode);
          this.CopyData(oldTargetOperation, (ITxRoboticOperation) null, oldTargetOperation.GetChildAt(i_child) as ITxRoboticOperation, currNode.MergeSchema);
        }
        else
          this.CopyData(oldTargetOperation, (ITxRoboticOperation) null, currNode.MatchedObject, currNode.MergeSchema);
      }
    }
  }

  private void CopyData(
    ITxOrderedObjectCollection oldTargetOperation,
    ITxRoboticOperation source,
    ITxRoboticOperation target,
    CUiROMDataUtils.MergeSchema mergeSchema)
  {
    try
    {
      if (this.m_isExcelIntropInstalled)
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PreCopyDataPrintToExcel(source, target)));
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultName || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateName || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaName || mergeSchema == CUiROMDataUtils.MergeSchema.Operation && CUiROMMergeSettings.CopyOperationName)
        this.CopyName(source, target);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultPosition || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternatePosition || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaPosition)
        this.CopyPosition(source, target);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultOrientationAll || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateOrientationAll || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaOrientationAll)
        this.CopyOrientation(oldTargetOperation, source, target, mergeSchema);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultExternalAxis || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateExternalAxis || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaExternalAxis)
      {
        this.CopyExternalAxes(source, target);
        this.CopyDepartExternalAxes(source, target);
      }
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultOlpCommands || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateOlpCommands || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaOlpCommands || mergeSchema == CUiROMDataUtils.MergeSchema.Operation && CUiROMMergeSettings.CopyOperationOlpCommands)
        this.CopyOlpCommands(source, target);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultRoboticParameters || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateRoboticParameters || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaRoboticParameters || mergeSchema == CUiROMDataUtils.MergeSchema.Operation && CUiROMMergeSettings.CopyOperationRoboticParameters)
        this.CopyRoboticParams(source, target);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultTaught || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateTaught || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaTaught)
        this.CopyTaughtPositionAndOrientation(source, target);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultRobotConfiguration || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateRobotConfiguration || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaRobotConfiguration)
        this.CopyConfiguration(source, target);
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultAttributes || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateAttributes || mergeSchema == CUiROMDataUtils.MergeSchema.Via && CUiROMMergeSettings.CopyViaAttributes || mergeSchema == CUiROMDataUtils.MergeSchema.Operation && CUiROMMergeSettings.CopyOperationAttributes)
        this.CopyAttributes(source, target);
      if (!this.m_isExcelIntropInstalled)
        return;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PostCopyDataPrintToExcel(source)));
    }
    catch (Exception ex)
    {
      int num = (int) TxMessageBox.Show(ex.Message + ex.StackTrace, CApROMStringTable.Robotic_Operation_Merge, MessageBoxButtons.OKCancel, MessageBoxIcon.Hand);
    }
  }

  private void CopyName(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    if (this.m_isExcelIntropInstalled)
    {
      string name = ((ITxObject) target).Name;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyNamePrintToExcel(name)));
    }
    if (source == null)
      return;
    if (!this.m_previewLog)
    {
      ((ITxObject) target).Name = ((ITxObject) source).Name;
      if (!this.m_isExcelIntropInstalled)
        return;
      string name = ((ITxObject) target).Name;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyNamePrintToExcel(name, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      string name = ((ITxObject) source).Name;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyNamePrintToExcel(name, 1)));
    }
  }

  internal void ShowExcel()
  {
    if (!this.m_isExcelIntropInstalled)
      return;
    this.m_excelManager.AddCall((Action) (() => this.m_excelManager.ShowExcel()));
    this.m_excelManager.AddCall(new Action(this.m_excelManager.RestoreCultureThread));
    this.m_excelManager.ActivateActions();
  }

  public void RestoreCultureThread()
  {
    if (!this.m_isExcelIntropInstalled)
      return;
    this.m_excelManager.RestoreCultureThread();
  }

  private void InitForMerge(
    CApROMMergeInfo[] newTargetOp,
    ITxObjectCollection weldLocationOperationContainer)
  {
    this.m_weldLocationContainer = weldLocationOperationContainer;
    for (int index = 0; index < newTargetOp.Length; ++index)
    {
      CApROMMergeInfo capRomMergeInfo = newTargetOp[index];
      if (capRomMergeInfo.MatchedObject != null)
      {
        if (capRomMergeInfo.MergeSchema == CUiROMDataUtils.MergeSchema.LocDefault)
          this.m_mergeAtLeastOneDefaultLoc = true;
        else if (capRomMergeInfo.MergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative)
          this.m_mergeAtLeastOneAlternateLoc = true;
        else if (capRomMergeInfo.MergeSchema == CUiROMDataUtils.MergeSchema.Via)
          this.m_mergeAtLeastOneViaLoc = true;
        else
          this.m_mergeAtLeastOneOperation = true;
      }
      if (capRomMergeInfo.TargetObject == null && (capRomMergeInfo.MergeSchema == CUiROMDataUtils.MergeSchema.LocDefault || capRomMergeInfo.MergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative) && capRomMergeInfo.MatchedObject is TxRoboticSeamLocationOperation)
        this.m_insertAtLeastOneSeamLoc = true;
    }
  }

  private void CheckIfProjectionParamsExist(CApROMMergeInfo[] newTargetOp)
  {
    this.m_projectionParamatersExist = false;
    CApROMMergeInfo capRomMergeInfo = newTargetOp[0];
    if (capRomMergeInfo.TargetObject.Parameters == null)
      return;
    foreach (TxRoboticParam parameter in capRomMergeInfo.TargetObject.Parameters)
    {
      if (parameter.Type.Equals("PROJECTION_TYPE"))
      {
        this.m_projectionParamatersExist = true;
        break;
      }
    }
  }

  private void CopyPosition(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    if (!(target is ITxLocatableObject))
      return;
    ITxLocatableObject itxLocatableObject = target as ITxLocatableObject;
    if (this.m_isExcelIntropInstalled)
    {
      TxTransformation tatget = itxLocatableObject.AbsoluteLocation;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTransformation(tatget)));
    }
    if (source == null || !(source is ITxLocatableObject))
      return;
    if (!this.m_previewLog)
    {
      TxTransformation absoluteLocation = itxLocatableObject.AbsoluteLocation;
      itxLocatableObject.AbsoluteLocation = new TxTransformation(new TxVector((source as ITxLocatableObject).AbsoluteLocation.Translation), new TxVector(absoluteLocation.RotationRPY_XYZ), (TxTransformation.TxRotationType) 1);
      if (!this.m_isExcelIntropInstalled)
        return;
      TxTransformation targetAbs = itxLocatableObject.AbsoluteLocation;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTransformation(targetAbs, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      TxTransformation sourceAbs = (source as ITxLocatableObject).AbsoluteLocation;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTransformation(sourceAbs, 1)));
    }
  }

  private void CopyOrientation(
    ITxOrderedObjectCollection oldTargetOperation,
    ITxRoboticOperation source,
    ITxRoboticOperation target,
    CUiROMDataUtils.MergeSchema mergeSchema)
  {
    if (!(target is ITxLocatableObject))
      return;
    ITxLocatableObject itxLocatableObject1 = target as ITxLocatableObject;
    if (this.m_isExcelIntropInstalled)
    {
      TxTransformation targetAbs = itxLocatableObject1.AbsoluteLocation;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintRotation(targetAbs)));
    }
    if (source == null || !(source is ITxLocatableObject))
      return;
    ITxLocatableObject itxLocatableObject2 = source as ITxLocatableObject;
    if (!this.m_previewLog)
    {
      if (mergeSchema == CUiROMDataUtils.MergeSchema.LocDefault && CUiROMMergeSettings.CopyDefaultOrientationExceptPerpendicular || mergeSchema == CUiROMDataUtils.MergeSchema.LocAlternative && CUiROMMergeSettings.CopyAlternateOrientationExceptPerpendicular)
      {
        TxLocationManipulationEx.CopyOrientationExceptPerpendicular(oldTargetOperation as ITxOrderedCompoundOperation, itxLocatableObject2, itxLocatableObject1);
      }
      else
      {
        TxTransformation absoluteLocation = itxLocatableObject1.AbsoluteLocation;
        itxLocatableObject1.AbsoluteLocation = new TxTransformation(new TxVector(itxLocatableObject1.AbsoluteLocation.Translation), new TxVector(itxLocatableObject2.AbsoluteLocation.RotationRPY_XYZ), (TxTransformation.TxRotationType) 1);
      }
      if (!this.m_isExcelIntropInstalled)
        return;
      TxTransformation targetAbs = itxLocatableObject1.AbsoluteLocation;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintRotation(targetAbs, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      TxTransformation sourceAbs = itxLocatableObject2.AbsoluteLocation;
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintRotation(sourceAbs, 1)));
    }
  }

  private void CopyExternalAxes(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    if (!(target is ITxRoboticLocationOperation))
      return;
    ITxRoboticLocationOperation locTarget = target as ITxRoboticLocationOperation;
    if (this.m_isExcelIntropInstalled)
    {
      string externalAxes = this.m_excelManager.GetExternalAxes(locTarget);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyExternalAxesPrintToExcel(externalAxes)));
    }
    if (source == null || !(source is ITxRoboticLocationOperation))
      return;
    if (!this.m_previewLog)
    {
      if (locTarget.RobotExternalAxesData != null)
        locTarget.RobotExternalAxesData = (TxRobotExternalAxisData[]) null;
      if ((source as ITxRoboticLocationOperation).RobotExternalAxesData == null)
        return;
      (target as ITxRoboticLocationOperation).RobotExternalAxesData = (source as ITxRoboticLocationOperation).RobotExternalAxesData;
      if (!this.m_isExcelIntropInstalled)
        return;
      string externalAxes = this.m_excelManager.GetExternalAxes(locTarget);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyExternalAxesPrintToExcel(externalAxes, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      string externalAxes = this.m_excelManager.GetExternalAxes(source as ITxRoboticLocationOperation);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyExternalAxesPrintToExcel(externalAxes, 1)));
    }
  }

  private void CopyDepartExternalAxes(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    if (!(target is ITxRoboticLocationOperation))
      return;
    ITxRoboticLocationOperation locTarget = target as ITxRoboticLocationOperation;
    if (this.m_isExcelIntropInstalled)
    {
      string externalAxis = this.m_excelManager.GetDepartExternalAxes(locTarget);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyDepartExternalAxesPrintToExcel(externalAxis)));
    }
    if (source == null || !(source is ITxRoboticLocationOperation))
      return;
    if (!this.m_previewLog)
    {
      if (locTarget.RobotDepartureExternalAxesData != null)
        locTarget.RobotDepartureExternalAxesData = (TxRobotExternalAxisData[]) null;
      if ((source as ITxRoboticLocationOperation).RobotDepartureExternalAxesData == null)
        return;
      (target as ITxRoboticLocationOperation).RobotDepartureExternalAxesData = (source as ITxRoboticLocationOperation).RobotDepartureExternalAxesData;
      if (!this.m_isExcelIntropInstalled)
        return;
      string externalAxis = this.m_excelManager.GetDepartExternalAxes(locTarget);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyDepartExternalAxesPrintToExcel(externalAxis, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      string externalAxis = this.m_excelManager.GetDepartExternalAxes(source as ITxRoboticLocationOperation);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyDepartExternalAxesPrintToExcel(externalAxis, 1)));
    }
  }

  private void CopyOlpCommands(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    if (this.m_isExcelIntropInstalled)
    {
      string allCommands = this.m_excelManager.AllOLPCommandUIRepresentations(target);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintOLPCommandUIRepresentations(allCommands)));
    }
    if (source == null)
      return;
    if (!this.m_previewLog)
    {
      if (target.Commands != null)
      {
        foreach (ITxObject command in (Collection<ITxObject>) target.Commands)
          command.Delete();
      }
      if (source.Commands != null)
      {
        foreach (ITxObject command1 in (Collection<ITxObject>) source.Commands)
        {
          if (command1 is TxRoboticCompositeCommand)
          {
            TxRoboticCompositeCommand compositeCommand1 = command1 as TxRoboticCompositeCommand;
            TxRoboticCompositeCommandCreationData commandCreationData = new TxRoboticCompositeCommandCreationData(compositeCommand1.Elements);
            ((TxObjectCreationData) commandCreationData).Name = ((TxRoboticCommand) compositeCommand1).Name;
            TxRoboticCompositeCommand compositeCommand2 = target.CreateCompositeCommand(commandCreationData);
            if (command1.Attributes != null)
            {
              foreach (TxAttribute attribute in command1.Attributes)
                ((TxRoboticCommand) compositeCommand2).SetAttribute(attribute);
            }
            ((TxRoboticCommand) compositeCommand2).Text = ((TxRoboticCommand) (command1 as TxRoboticCompositeCommand)).Text;
          }
          else if (command1 is TxRoboticCommand)
          {
            TxRoboticCommand txRoboticCommand = command1 as TxRoboticCommand;
            TxRoboticCommandCreationData commandCreationData = new TxRoboticCommandCreationData(txRoboticCommand.Text);
            ((TxObjectCreationData) commandCreationData).Name = txRoboticCommand.Name;
            TxRoboticCommand command2 = target.CreateCommand(commandCreationData);
            if (command1.Attributes != null)
            {
              foreach (TxAttribute attribute in command1.Attributes)
                command2.SetAttribute(attribute);
            }
          }
        }
      }
      if (!this.m_isExcelIntropInstalled)
        return;
      string allCommands = this.m_excelManager.AllOLPCommandUIRepresentations(target);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintOLPCommandUIRepresentations(allCommands, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      string allCommands = this.m_excelManager.AllOLPCommandUIRepresentations(source);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintOLPCommandUIRepresentations(allCommands, 1)));
    }
  }

  private void CopyAttributes(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    string value = "";
    if (((ITxObject) target).Attributes != null)
    {
      foreach (TxAttribute attribute in ((ITxObject) target).Attributes)
      {
        this.PrintAttribute(ref value, attribute);
        if (source != null && !this.m_previewLog)
          ((ITxObject) target).RemoveAttribute(attribute.Name);
      }
    }
    if (this.m_isExcelIntropInstalled)
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintAttributesToExcel(value)));
    if (source == null)
      return;
    value = "";
    if (((ITxObject) source).Attributes != null)
    {
      foreach (TxAttribute attribute in ((ITxObject) source).Attributes)
      {
        this.PrintAttribute(ref value, attribute);
        if (!this.m_previewLog)
          ((ITxObject) target).SetAttribute(attribute);
      }
    }
    if (!this.m_isExcelIntropInstalled)
      return;
    this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintAttributesToExcel(value, 1)));
  }

  private void CopyTaughtPositionAndOrientation(
    ITxRoboticOperation source,
    ITxRoboticOperation target)
  {
    TxRoboticTransformationParam transformationParam1 = new TxRoboticTransformationParam();
    TxRoboticTransformationParam parameter1 = (TxRoboticTransformationParam) target.GetParameter("POSITION_IN_SIMULATION");
    TxRoboticTxObjectParam objParamTarget = new TxRoboticTxObjectParam();
    this.GetDynamicRefFrame(target as ITxRoboticLocationOperation, ref objParamTarget);
    if (this.m_isExcelIntropInstalled)
    {
      if (parameter1 != null)
      {
        TxTransformation transformation = parameter1.Value;
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTaughtTransformation(transformation)));
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTaughtRotation(transformation)));
      }
      if (objParamTarget != null)
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyDynamicRefFramePrintToExcel(objParamTarget)));
    }
    if (source == null)
      return;
    TxRoboticTransformationParam transformationParam2 = new TxRoboticTransformationParam();
    TxRoboticTransformationParam parameter2 = (TxRoboticTransformationParam) source.GetParameter("POSITION_IN_SIMULATION");
    TxRoboticTxObjectParam dynamicRefFrameId = new TxRoboticTxObjectParam();
    this.GetDynamicRefFrame(source as ITxRoboticLocationOperation, ref dynamicRefFrameId);
    if (parameter2 != null)
    {
      TxRoboticTransformationParam locNew = new TxRoboticTransformationParam(parameter2);
      if (!this.m_previewLog)
        target.RemoveParameter("POSITION_IN_SIMULATION");
      this.CalculateNewTaughtParameters(parameter1, objParamTarget, parameter2, dynamicRefFrameId, ref locNew);
      if (!this.m_previewLog)
        target.SetParameter((TxRoboticParam) locNew);
      if (this.m_isExcelIntropInstalled)
      {
        TxTransformation transformation = parameter1.Value;
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTaughtTransformation(transformation, 1)));
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintTaughtRotation(transformation, 1)));
      }
    }
    if (!this.m_isExcelIntropInstalled || objParamTarget == null)
      return;
    this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyDynamicRefFramePrintToExcel(objParamTarget, 1)));
  }

  private void CopyConfiguration(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    if (!(target is ITxRoboticLocationOperation))
      return;
    if ((target as ITxRoboticLocationOperation).RobotConfigurationData != null)
    {
      if (this.m_isExcelIntropInstalled)
      {
        string configurationString = this.m_excelManager.ConfigurationString(target);
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyConfigurationPrintToExcel(configurationString)));
      }
      if (source != null && source is ITxRoboticLocationOperation && !this.m_previewLog)
        (target as ITxRoboticLocationOperation).RobotConfigurationData = (TxRobotConfigurationData) null;
    }
    if (source == null || (source as ITxRoboticLocationOperation).RobotConfigurationData == null)
      return;
    if (!this.m_previewLog)
    {
      (target as ITxRoboticLocationOperation).RobotConfigurationData = (source as ITxRoboticLocationOperation).RobotConfigurationData;
      if (!this.m_isExcelIntropInstalled)
        return;
      string configurationString = this.m_excelManager.ConfigurationString(target);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyConfigurationPrintToExcel(configurationString, 1)));
    }
    else
    {
      if (!this.m_isExcelIntropInstalled)
        return;
      string configurationString = this.m_excelManager.ConfigurationString(source);
      this.m_excelManager.AddCall((Action) (() => this.m_excelManager.CopyConfigurationPrintToExcel(configurationString, 1)));
    }
  }

  internal void KillExcel() => this.m_excelManager.KillExcel();

  private void CopyRoboticParams(ITxRoboticOperation source, ITxRoboticOperation target)
  {
    string value = "";
    if (target.Parameters != null)
    {
      foreach (TxRoboticParam parameter in target.Parameters)
      {
        if (!parameter.Type.Equals("POSITION_IN_SIMULATION") && !parameter.Type.Equals("DYNAMIC_REFERENCE_FRAME") && !parameter.Type.Equals("PROJECTION_TYPE") && !parameter.Type.Equals("ARC_ALIGNMENT_XML_PARAMS") && !parameter.Type.Equals("PROJECTION_XML_PARAMS"))
        {
          value += this.PrintRoboticParams(parameter);
          if (source != null && !this.m_previewLog)
            target.RemoveParameter(parameter.Type);
        }
      }
      if (this.m_isExcelIntropInstalled)
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintRoboticParamsToExcel(value)));
    }
    string sourceValue = "";
    if (source == null || source.Parameters == null)
      return;
    foreach (TxRoboticParam parameter in source.Parameters)
    {
      if (!parameter.Type.Equals("POSITION_IN_SIMULATION") && !parameter.Type.Equals("DYNAMIC_REFERENCE_FRAME") && !parameter.Type.Equals("PROJECTION_TYPE") && !parameter.Type.Equals("ARC_ALIGNMENT_XML_PARAMS") && !parameter.Type.Equals("PROJECTION_XML_PARAMS"))
      {
        sourceValue += this.PrintRoboticParams(parameter);
        if (!this.m_previewLog)
          target.SetParameter(parameter);
      }
    }
    if (!this.m_isExcelIntropInstalled)
      return;
    this.m_excelManager.AddCall((Action) (() => this.m_excelManager.PrintRoboticParamsToExcel(sourceValue, 1)));
  }

  private string PrintRoboticParams(TxRoboticParam param)
  {
    string str = "";
    try
    {
      str = param.Type + " : ";
      switch (param)
      {
        case TxRoboticIntParam _:
          str += (param as TxRoboticIntParam).Value.ToString();
          break;
        case TxRoboticDoubleParam _:
          str += (param as TxRoboticDoubleParam).Value.ToString();
          break;
        case TxRoboticStringParam _:
          str += (param as TxRoboticStringParam).Value;
          break;
        case TxRoboticTransformationParam _:
          str += (param as TxRoboticTransformationParam).Value.ToString();
          break;
        case TxRoboticTxObjectParam _:
          str += (param as TxRoboticTxObjectParam).Value.Name;
          break;
      }
      str += "\n";
    }
    catch (Exception ex)
    {
    }
    return str;
  }

  private void PrintAttribute(ref string value, TxAttribute att)
  {
    try
    {
      value = $"{value}{att.Name}: ";
      switch (att)
      {
        case TxDoubleAttribute _:
          value += (att as TxDoubleAttribute).Value.ToString();
          break;
        case TxIntAttribute _:
          value += (att as TxIntAttribute).Value.ToString();
          break;
        case TxStringAttribute _:
          value += (att as TxStringAttribute).Value.ToString();
          break;
        case TxVectorAttribute _:
          value += (att as TxVectorAttribute).Value.ToString();
          break;
        case TxTransformationAttribute _:
          value += (att as TxTransformationAttribute).Value.ToString();
          break;
      }
      value += "\n";
    }
    catch (Exception ex)
    {
    }
  }

  private void CalculateNewTaughtParameters(
    TxRoboticTransformationParam locTarget,
    TxRoboticTxObjectParam refFrameIdTarget,
    TxRoboticTransformationParam locSource,
    TxRoboticTxObjectParam refFrameIdSource,
    ref TxRoboticTransformationParam locNew)
  {
    if (refFrameIdSource == null)
    {
      if (refFrameIdTarget == null)
      {
        locNew.Value = locSource.Value;
      }
      else
      {
        TxTransformation absoluteLocation = (refFrameIdTarget.Value as ITxLocatableObject).AbsoluteLocation;
        locNew.Value = TxTransformation.op_Multiply(absoluteLocation.Inverse, locSource.Value);
      }
    }
    else
    {
      TxTransformation absoluteLocation1 = (refFrameIdSource.Value as ITxLocatableObject).AbsoluteLocation;
      if (refFrameIdTarget == null)
      {
        locNew.Value = TxTransformation.op_Multiply(absoluteLocation1, locSource.Value);
      }
      else
      {
        TxTransformation absoluteLocation2 = (refFrameIdTarget.Value as ITxLocatableObject).AbsoluteLocation;
        locNew.Value = TxTransformation.op_Multiply(absoluteLocation2.Inverse, TxTransformation.op_Multiply(absoluteLocation1, locSource.Value));
      }
    }
  }

  private void GetDynamicRefFrame(
    ITxRoboticLocationOperation loc,
    ref TxRoboticTxObjectParam dynamicRefFrameId)
  {
    dynamicRefFrameId = (TxRoboticTxObjectParam) null;
    ITxObjectCollection collection1 = ((ITxObject) loc).Collection;
    if (collection1 == null)
      return;
    ITxObjectCollection collection2 = ((ITxObject) collection1).Collection;
    if (collection2 != null && collection2 is ITxRoboticOperation)
      dynamicRefFrameId = (((ITxObject) collection1).Collection as ITxRoboticOperation).GetParameter("DYNAMIC_REFERENCE_FRAME") as TxRoboticTxObjectParam;
    else
      dynamicRefFrameId = (collection1 as ITxRoboticOperation).GetParameter("DYNAMIC_REFERENCE_FRAME") as TxRoboticTxObjectParam;
  }

  private bool ShouldInsertNameColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultName || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateName || this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaName)
      return true;
    return this.m_mergeAtLeastOneOperation && CUiROMMergeSettings.CopyOperationName;
  }

  private bool ShouldInsertPositionColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultPosition || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternatePosition)
      return true;
    return this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaPosition;
  }

  private bool ShouldInsertOrientationColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultOrientationAll || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateOrientationAll || this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaOrientationAll || this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultOrientationExceptPerpendicular)
      return true;
    return this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateOrientationExceptPerpendicular;
  }

  private bool ShouldInsertExternalAxisColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultExternalAxis || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateExternalAxis)
      return true;
    return this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaExternalAxis;
  }

  private bool ShouldInsertOLPCommandsColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultOlpCommands || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateOlpCommands || this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaOlpCommands)
      return true;
    return this.m_mergeAtLeastOneOperation && CUiROMMergeSettings.CopyOperationOlpCommands;
  }

  private bool ShouldInsertRoboticParametersColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultRoboticParameters || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateRoboticParameters || this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaRoboticParameters)
      return true;
    return this.m_mergeAtLeastOneOperation && CUiROMMergeSettings.CopyOperationRoboticParameters;
  }

  private bool ShouldInsertTaughtPositionAndOrientationColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultTaught || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateTaught)
      return true;
    return this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaTaught;
  }

  private bool ShouldInsertConfigurationColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultRobotConfiguration || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateRobotConfiguration)
      return true;
    return this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaRobotConfiguration;
  }

  private bool ShouldInsertAttributesColumn()
  {
    if (this.m_mergeAtLeastOneDefaultLoc && CUiROMMergeSettings.CopyDefaultAttributes || this.m_mergeAtLeastOneAlternateLoc && CUiROMMergeSettings.CopyAlternateAttributes || this.m_mergeAtLeastOneViaLoc && CUiROMMergeSettings.CopyViaAttributes)
      return true;
    return this.m_mergeAtLeastOneOperation && CUiROMMergeSettings.CopyOperationAttributes;
  }

  private void DeleteRemovedObjectsFromContOp(TxObjectList removedObjects)
  {
    TxObjectList txObjectList = new TxObjectList();
    foreach (ITxObject removedObject in (Collection<ITxObject>) removedObjects)
    {
      if (removedObject is TxRoboticSeamLocationOperation)
        removedObject.Delete();
      else
        ((Collection<ITxObject>) txObjectList).Add(removedObject);
    }
    foreach (ITxObject itxObject in (Collection<ITxObject>) txObjectList)
    {
      if (itxObject is ITxRoboticOperation)
        itxObject.Delete();
    }
  }

  private void ReorderInContOpTarget(
    ITxOrderedObjectCollection oldTargetOp,
    ref int i_child,
    int i_currNode,
    CApROMMergeInfo[] newTargetOp)
  {
    CApROMMergeInfo capRomMergeInfo = newTargetOp[i_currNode];
    if (capRomMergeInfo.TargetObject is TxRoboticViaLocationOperation)
    {
      ++i_child;
      if (capRomMergeInfo.TargetObject == oldTargetOp.GetChildAt(i_child) || this.m_previewLog)
        return;
      if (i_child == 0)
      {
        if (!oldTargetOp.CanMoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null))
          return;
        oldTargetOp.MoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null);
      }
      else
      {
        if (!oldTargetOp.CanMoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, oldTargetOp.GetChildAt(i_child - 1)))
          return;
        oldTargetOp.MoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, oldTargetOp.GetChildAt(i_child - 1));
      }
    }
    else
    {
      if (!(capRomMergeInfo.TargetObject is TxRoboticSeamOperation))
        return;
      ++i_child;
      this.ReorderSeamOpInContOpTarget(oldTargetOp, i_child, i_currNode, newTargetOp);
    }
  }

  private void ReorderInSeamOpTarget(
    ITxOrderedObjectCollection oldTargetOp,
    ref int i_child,
    int i_currNode,
    CApROMMergeInfo[] newTargetOp)
  {
    CApROMMergeInfo capRomMergeInfo = newTargetOp[i_currNode];
    ++i_child;
    if (capRomMergeInfo.TargetObject == oldTargetOp.GetChildAt(i_child))
      return;
    TxRoboticSeamOperation targetObject = newTargetOp[0].TargetObject as TxRoboticSeamOperation;
    if (this.m_previewLog)
      return;
    if (i_child == 0)
    {
      if (!TxRoboticSeamOperationEx.CanMoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null))
        return;
      TxRoboticSeamOperationEx.MoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null);
    }
    else
    {
      if (!TxRoboticSeamOperationEx.CanMoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, oldTargetOp.GetChildAt(i_child - 1)))
        return;
      TxRoboticSeamOperationEx.MoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, oldTargetOp.GetChildAt(i_child - 1));
    }
  }

  private void ReorderSeamOpInContOpTarget(
    ITxOrderedObjectCollection oldTargetContOp,
    int i_child,
    int i_seamOpNode,
    CApROMMergeInfo[] newTargetContOp)
  {
    CApROMMergeInfo capRomMergeInfo = newTargetContOp[i_seamOpNode];
    if (!this.m_previewLog && capRomMergeInfo.TargetObject != oldTargetContOp.GetChildAt(i_child))
    {
      if (i_child == 0)
      {
        if (oldTargetContOp.CanMoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null))
          oldTargetContOp.MoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null);
      }
      else if (oldTargetContOp.CanMoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, oldTargetContOp.GetChildAt(i_child - 1)))
        oldTargetContOp.MoveChildAfter((ITxObject) capRomMergeInfo.TargetObject, oldTargetContOp.GetChildAt(i_child - 1));
    }
    this.ReorderSeamLocsInContOpTarget(capRomMergeInfo.TargetObject as ITxOrderedObjectCollection, i_seamOpNode, newTargetContOp);
  }

  private void ReorderSeamLocsInContOpTarget(
    ITxOrderedObjectCollection oldTargetSeamOp,
    int i_seamOpNode,
    CApROMMergeInfo[] newTargetContOp)
  {
    if (i_seamOpNode + 1 >= newTargetContOp.Length)
      return;
    bool flag = false;
    int i_seamLoc = 0;
    TxRoboticSeamOperation targetObject = newTargetContOp[i_seamOpNode].TargetObject as TxRoboticSeamOperation;
    for (int index = i_seamOpNode + 1; index < newTargetContOp.Length && !flag; ++index)
    {
      CApROMMergeInfo capRomMergeInfo = newTargetContOp[index];
      if (capRomMergeInfo.TargetObject == null)
      {
        if (capRomMergeInfo.MatchedObject == null || !(capRomMergeInfo.MatchedObject is TxRoboticSeamLocationOperation))
        {
          flag = true;
        }
        else
        {
          ITxLocatableObject matchedObject = capRomMergeInfo.MatchedObject as ITxLocatableObject;
          if (!this.m_previewLog)
          {
            if (this.InsertSeamLocToSeamOp(matchedObject, targetObject, i_seamLoc))
            {
              this.CopyData((ITxOrderedObjectCollection) targetObject, (ITxRoboticOperation) null, targetObject.GetChildAt(i_seamLoc) as ITxRoboticOperation, CUiROMDataUtils.MergeSchema.LocDefault);
              ++i_seamLoc;
            }
          }
          else
            this.CopyData((ITxOrderedObjectCollection) targetObject, (ITxRoboticOperation) null, targetObject.GetChildAt(i_seamLoc) as ITxRoboticOperation, CUiROMDataUtils.MergeSchema.LocDefault);
        }
      }
      else if (capRomMergeInfo.TargetObject is TxRoboticSeamLocationOperation)
      {
        if (capRomMergeInfo.TargetObject != targetObject.GetChildAt(i_seamLoc) && !this.m_previewLog)
        {
          if (i_seamLoc == 0)
          {
            if (TxRoboticSeamOperationEx.CanMoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null))
              TxRoboticSeamOperationEx.MoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, (ITxObject) null);
          }
          else if (TxRoboticSeamOperationEx.CanMoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, targetObject.GetChildAt(i_seamLoc - 1)))
            TxRoboticSeamOperationEx.MoveChildAfterEx(targetObject, (ITxObject) capRomMergeInfo.TargetObject, targetObject.GetChildAt(i_seamLoc - 1));
        }
        if (capRomMergeInfo.MatchedObject != null)
          this.CopyData((ITxOrderedObjectCollection) targetObject, capRomMergeInfo.MatchedObject, capRomMergeInfo.TargetObject, capRomMergeInfo.MergeSchema);
        ++i_seamLoc;
      }
      else
        flag = true;
    }
  }

  private bool InsertSeamLocToSeamOp(
    ITxLocatableObject seamLoc,
    TxRoboticSeamOperation seamOp,
    int i_seamLoc)
  {
    if (seamOp.Count <= 0)
    {
      TxMessageBox.Show(this.GetResourceManager().GetString("INSERT_FAILED_NO_SEAM_LOCS"), this.GetResourceManager().GetString("WARNING_CAPTION"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
      return false;
    }
    TxRoboticSeamLocationOperation childAt1 = (TxRoboticSeamLocationOperation) seamOp.GetChildAt(0);
    TxTransformation projectedLocation = ((TxRoboticSeamLocationOperation) seamLoc).ProjectedLocation;
    CApIlisInsertLocInsideSeam insertLocInsideSeam = new CApIlisInsertLocInsideSeam();
    TxRoboticSeamLocationOperation seamLocation;
    if (i_seamLoc == 0)
    {
      seamLocation = insertLocInsideSeam.CreateSeamLocation(seamOp, childAt1, projectedLocation, false);
      if (TxRoboticSeamLocationOperation.op_Inequality(seamLocation, (ITxObject) null))
        seamLocation.Name = ((ITxObject) seamLoc).Name;
    }
    else
    {
      TxRoboticSeamLocationOperation childAt2 = (TxRoboticSeamLocationOperation) seamOp.GetChildAt(i_seamLoc - 1);
      seamLocation = insertLocInsideSeam.CreateSeamLocation(seamOp, childAt2, projectedLocation, true);
      if (TxRoboticSeamLocationOperation.op_Inequality(seamLocation, (ITxObject) null))
        seamLocation.Name = ((ITxObject) seamLoc).Name;
    }
    return TxRoboticSeamLocationOperation.op_Inequality(seamLocation, (ITxObject) null);
  }

  private void CreateInTarget(
    ITxOrderedObjectCollection oldTargetOp,
    ref int i_child,
    CApROMMergeInfo currNode)
  {
    TxObjectList txObjectList = new TxObjectList();
    ((Collection<ITxObject>) txObjectList).Add((ITxObject) currNode.MatchedObject);
    ((ITxObjectCollection) oldTargetOp).Paste(txObjectList);
    ++i_child;
    if (((ITxObjectCollection) oldTargetOp).Count == 1)
      return;
    if (i_child == 0)
    {
      if (!oldTargetOp.CanMoveChildAfter(oldTargetOp.GetChildAt(((ITxObjectCollection) oldTargetOp).Count - 1), (ITxObject) null))
        return;
      oldTargetOp.MoveChildAfter(oldTargetOp.GetChildAt(((ITxObjectCollection) oldTargetOp).Count - 1), (ITxObject) null);
    }
    else
    {
      if (!oldTargetOp.CanMoveChildAfter(oldTargetOp.GetChildAt(((ITxObjectCollection) oldTargetOp).Count - 1), oldTargetOp.GetChildAt(i_child - 1)))
        return;
      oldTargetOp.MoveChildAfter(oldTargetOp.GetChildAt(((ITxObjectCollection) oldTargetOp).Count - 1), oldTargetOp.GetChildAt(i_child - 1));
    }
  }

  private void AddRemovedObjectToNameData(ITxObject toDeleteObject, RemoveAction action)
  {
    string format1 = this.GetResourceManager().GetString("LOG_DELTED_OBJECT_FORMAT");
    string str1 = toDeleteObject.GetType().ToString();
    int num = str1.LastIndexOf('.');
    if (num >= 0)
      str1 = str1.Substring(num + 1);
    string str2;
    if (action == RemoveAction.Deleted)
    {
      str2 = this.GetResourceManager().GetString("LOG_DELETED_OBJECT_FORMAT");
    }
    else
    {
      string format2 = action != RemoveAction.Moved ? this.GetResourceManager().GetString("LOG_MOVE_DENIED_OBJECT_FORMAT") : this.GetResourceManager().GetString("LOG_MOVE_OBJECT_FORMAT");
      string name = ((ITxObject) this.m_weldLocationContainer).Name;
      if (string.IsNullOrEmpty(name) && this.m_weldLocationContainer == TxApplication.ActiveDocument.OperationRoot)
        name = this.GetResourceManager().GetString("LOG_MOVE_OPERATION_ROOT");
      str2 = string.Format(format2, (object) name);
    }
    this.m_removedObjectNameData.Add(new Tuple<string, string, RemoveAction>(string.Format(format1, (object) toDeleteObject.Name, (object) str2, (object) str1), toDeleteObject.Name, action));
  }

  private void LogRemovedObjects()
  {
    if (!this.m_isExcelIntropInstalled)
      return;
    if (this.m_removedObjectNameData.Count > 0)
    {
      foreach (Tuple<string, string, RemoveAction> tuple in this.m_removedObjectNameData)
      {
        Tuple<string, string, RemoveAction> objectData = tuple;
        this.m_excelManager.AddCall((Action) (() => this.m_excelManager.LogRemovedObjects(objectData)));
      }
    }
    this.m_removedObjectNameData.Clear();
  }

  private ResourceManager GetResourceManager()
  {
    return new ResourceManager("DnProcessSimulateCommands.RoboticOperationMerge.Res.ResourceTable", this.GetType().Assembly);
  }
}
